/**
 @file sys_usw_qos.h

 @date 2010-01-13

 @version v2.0

 The file defines queue api
*/

#ifndef _SYS_USW_QOS_H
#define _SYS_USW_QOS_H

#ifdef __cplusplus
extern "C" {
#endif

/***************************************************************
 *
 * Header Files
 *
 ***************************************************************/
#include "ctc_const.h"
#include "ctc_debug.h"
#include "ctc_vector.h"
#include "ctc_spool.h"
#include "ctc_hash.h"
#include "ctc_stats.h"
#include "ctc_parser.h"
#include "ctc_packet.h"
#include "ctc_qos.h"
#include "ctc_warmboot.h"
#include "sys_usw_qos_api.h"
#include "sys_usw_register.h"

/*********************************************************************
*
* Data Structure
*
*********************************************************************/
/****************************** cpu reason ******************************/
#define SYS_REASON_ENCAP_EXCP(type, excp, sub_excp)  ((type << 9) | ((excp) + (sub_excp)))
#define SYS_REASON_GET_EXCP_TYPE(exception) (exception >> 9)
#define SYS_REASON_GET_EXCP_INDEX(exception) (exception & 0x1FF)
/*sub_queue_id/MCHIP_CAP(SYS_CAP_REASON_GRP_QUEUE_NUM)*MCHIP_CAP(SYS_CAP_REASON_GRP_QUEUE_NUM)*/
#define SYS_REASON_GET_GROUP_ID(sub_queue_id) (sub_queue_id & 0xf8)

/****************************** queue enq ******************************/
#define SYS_QOS_QUEUE_DBG_OUT(level, FMT, ...) \
    do { \
        CTC_DEBUG_OUT(qos, queue, QOS_QUE_SYS, level, FMT, ##__VA_ARGS__); \
    } while (0);

#define SYS_QOS_GET_SHAPE_TOKEN_THRD(is_pps, token_thrd) {\
   if (is_pps)\
   {\
      token_thrd = token_thrd/MCHIP_CAP(SYS_CAP_QOS_SHP_PPS_PACKET_BYTES); /*pps*/ \
   }\
   else\
   {\
      token_thrd = token_thrd/125; /*kb*/ \
   }\
}
#define SYS_MAX_CHANNEL_NUM  512
#define SYS_C2C_QUEUE_NUM 8
#define SYS_LCPU_QUEUE_NUM           ((p_usw_queue_master[lchip]->max_dma_rx_num == 1) ? 64 : 128)
#define SYS_C2C_QUEUE_MODE(lchip)  (!((1 == p_usw_queue_master[lchip]->enq_mode) && (DRV_IS_DUET2(lchip))))
#define SYS_QOS_TOTAL_QUEUE_NUM    12288
#define SYS_STACKING_PORT_NUM        4
#define SYS_GRP_SHP_CBUCKET_NUM       8
/*at lease one packet's mtu*/
#define SYS_QOS_MTU    9600
#define SYS_WFQ_DEFAULT_WEIGHT    1
#define SYS_WFQ_DEFAULT_SHIFT      2
#define SYS_SHP_GRAN_RANAGE_NUM   8
#define SYS_SHAPE_MAX_TOKEN_THRD    ((1 << 8) -1)
#define SYS_RESRC_MAX_CONGEST_LEVEL_NUM 4
#define SYS_SVC_POLICER_STATS_MODE_MAX 3
#define SYS_POLICER_STATS_MODE_MAX 1
#define SYS_PRIO_CLASS_NUM     8
#define SYS_PORT_GUARANTEE_PROF_NUM     8
#define SYS_QOS_EGRESS_SC_POOL_NUM 4
#define SYS_NORMAL_QUEUE_NUM  8
#define SYS_AT_MC_QUEUE_NUM  6
#define SYS_AT_UC_QUEUE_NUM  12
#define SYS_WRED_EWMA_MAX_WEIGHT 15

#define QOS_LOCK \
    if (p_usw_qos_master[lchip]->p_qos_mutex) sal_mutex_lock(p_usw_qos_master[lchip]->p_qos_mutex)
#define QOS_UNLOCK \
    if (p_usw_qos_master[lchip]->p_qos_mutex) sal_mutex_unlock(p_usw_qos_master[lchip]->p_qos_mutex)
    
#define SYS_QOS_POLICER_SVC_SUPPORT_STORM_CTL(lchip) (p_usw_qos_policer_master[lchip]->policer_svc_mode & (CTC_QOS_POLICER_SVC_MODE_FID_STORMCTL | CTC_QOS_POLICER_SVC_MODE_VLAN_STORMCTL))

#define SYS_GROUP_ID_BY_CHAN(chan_id) ((chan_id) > MCHIP_CAP(SYS_CAP_CHANID_DMA_RX0) ? ((chan_id) - 1) : (chan_id))
#define SYS_GROUP_ID(queue_id)  ((queue_id < MCHIP_CAP(SYS_CAP_QOS_QUEUE_BASE_MISC)) ? (queue_id/MCHIP_CAP(SYS_CAP_QOS_QUEUE_NUM_PER_GRP)) : (MCHIP_CAP(SYS_CAP_QOS_BASE_QUEUE_GRP_NUM) + ((queue_id-MCHIP_CAP(SYS_CAP_QOS_QUEUE_BASE_EXT))/MCHIP_CAP(SYS_CAP_QOS_QUEUE_NUM_PER_EXT_GRP))))
#define SYS_EXT_GROUP_ID(queue_id, ext_grp_id)  \
    if(((queue_id) >= MCHIP_CAP(SYS_CAP_QOS_QUEUE_BASE_EXT))) \
        { (ext_grp_id) = (((queue_id)-MCHIP_CAP(SYS_CAP_QOS_QUEUE_BASE_EXT))/MCHIP_CAP(SYS_CAP_QOS_QUEUE_NUM_PER_EXT_GRP));}

#define SYS_IS_EXT_GROUP(group_id) ((group_id >= MCHIP_CAP(SYS_CAP_QOS_BASE_QUEUE_GRP_NUM)) && (group_id <  MCHIP_CAP(SYS_CAP_QOS_GROUP_NUM)))
#define SYS_IS_BASE_GROUP(group_id) (group_id < MCHIP_CAP(SYS_CAP_QOS_BASE_QUEUE_GRP_NUM))

#define SYS_IS_DMA_CHANNEL(channel) ((channel >= MCHIP_CAP(SYS_CAP_CHANID_DMA_RX0)) && (channel <= MCHIP_CAP(SYS_CAP_CHANID_DMA_RX3)))
#define SYS_RESRC_IGS_MAX_PORT_MIN_PROFILE   7

#define SYS_RESRC_PROFILE_QUEUE 0
#define SYS_RESRC_PROFILE_FC 1
#define SYS_RESRC_PROFILE_PFC 2
#define SYS_RESRC_PROFILE_MAX 3

#define SYS_ERM_PROFILE_DEFAULT 0
#define SYS_ERM_PROFILE_USER_DEFINE 1
#define SYS_ERM_PROFILE_CPU_PKT 2
#define SYS_ERM_PROFILE_DESTMAP_ENQ 3
#define SYS_ERM_PROFILE_LOGIC_SRC_PORT_ENQ 4
#define SYS_ERM_PROFILE_ETS 5
#define SYS_ERM_PROFILE_MOD 6
#define SYS_ERM_PROFILE_USER_DEFINE2 7 /*for AT*/
#define SYS_ERM_PROFILE_NH_GROUP 7
#define SYS_ERM_PROFILE_MAX_NUM 8

#define SYS_QUE_MAP_TYPE_UC 0
#define SYS_QUE_MAP_TYPE_MC 1
#define SYS_QUE_MAP_TYPE_SPAN 2
#define SYS_QUE_MAP_TYPE_CPU_PKT 3
#define SYS_QUE_MAP_TYPE_CPU_PKT_PRIO 4
#define SYS_QUE_MAP_TYPE_C2C 5
#define SYS_QUE_MAP_TYPE_UNKNOWN_MC 6
#define SYS_QUE_MAP_TYPE_OAM 7
#define SYS_QUE_MAP_TYPE_MAX_NUM 8
#define SYS_QUE_MAP_OFFSET_MODE_CTL_QUE 4
#define SYS_QUE_MAP_OFFSET_MODE_ETS_QUE 5
#define SYS_QUE_MAP_OFFSET_MODE_CPU_QUE 6
#define SYS_QUE_MAP_OFFSET_MODE_CPU_PRIO_QUE 7
#define SYS_QUE_MAP_ENQ_BY_SERVICE_ID 0
#define SYS_QUE_MAP_ENQ_BY_LOGIC_SRC_PORT 1
#define SYS_QUE_MAP_ENQ_BY_LOGIC_DST_PORT_OR_NEXTHOPPTR 2
#define SYS_QUE_MAP_ENQ_BY_DESTMAP 3

#define SYS_QUE_MAP_OFFSET_CTL_QUE_MC 1
#define SYS_QUE_MAP_OFFSET_CTL_QUE_SPAN 0
#define SYS_QUE_MAP_OFFSET_CTL_QUE_CPU 2
#define SYS_QUE_MAP_OFFSET_CTL_QUE_C2C 3
#define SYS_QUE_MAX_REQ_NUM_MC 2

#define QOS_SCHED_MAX_QUE_CLASS 7
#define QOS_SCHED_MAX_EXT_QUE_CLASS 3
#define QOS_SCHED_MAX_CHAN_CLASS 3
#define SYS_SCHED_MAX_ETS_EXT_GRP_NUM    3.
#define QOS_SCHED_MAX_REQ_CLASS 3

#define INVALID_QUEUE_GROUP_ID_ETS   0xFFFF

#define SYS_QOS_OOBFC_MAX_GROUP_NUM          256
#define SYS_QOS_OOBFC_EGRESS_MAX_TC_NUM      8
#define SYS_QOS_OOBFC_INGRESS_MAX_STALL_NUM  32

#define SYS_MAX_FCDL_RECOVER_INTERVAL 50
#define SYS_MAX_FCDL_INTERVAL_TIME 53
#define SYS_MAX_FCDL_MULT_NUM 255

#define SYS_QOS_QUEUE_ENQ_PRIORITY_MAX      15
#define SYS_QOS_QUEUE_ENQ_COLOR_MIN     (CTC_QOS_COLOR_RED)
#define SYS_QOS_QUEUE_ENQ_COLOR_MAX     (MAX_CTC_QOS_COLOR - 1)
#define SYS_QOS_QUEUE_ENQ_QUEUE_SELECT_MAX  7
#define SYS_QOS_QUEUE_ENQ_ROP_PRECEDENCE_MAX    3

/*
* sch sub group to group vector index, for sch_group_vector
*/
#define SYS_SUB_GRP_TO_GRP_VEC_INDEX(grp_vec_index, level, sub_grp_id) \
    { \
        uint8  lvl_index = 0; \
        uint32 lvl_grp_num[CTC_QOS_SCHED_GROUP_LVL_MAX] = {MCHIP_CAP(SYS_CAP_QOS_L0_GRP_NUM), MCHIP_CAP(SYS_CAP_QOS_L1_GRP_NUM), \
                                                         MCHIP_CAP(SYS_CAP_QOS_L2_GRP_NUM), MCHIP_CAP(SYS_CAP_QOS_L3_GRP_NUM), \
                                                         MCHIP_CAP(SYS_CAP_QOS_QUE_GRP_NUM)}; \
        grp_vec_index = 0; \
        for (lvl_index = 0; lvl_index < level; lvl_index++) \
        {\
            grp_vec_index += lvl_grp_num[lvl_index];\
        }\
        grp_vec_index += sub_grp_id; \
    } \

#define SYS_GRP_VEC_INDEX_TO_SUB_GRP(grp_vec_index, level, sub_grp_id) \
    { \
        uint32 tmp_vec_index = 0; \
        uint8  lvl_index = 0; \
        uint32 lvl_grp_num[CTC_QOS_SCHED_GROUP_LVL_MAX] = {MCHIP_CAP(SYS_CAP_QOS_L0_GRP_NUM), MCHIP_CAP(SYS_CAP_QOS_L1_GRP_NUM), \
                                                         MCHIP_CAP(SYS_CAP_QOS_L2_GRP_NUM), MCHIP_CAP(SYS_CAP_QOS_L3_GRP_NUM), \
                                                         MCHIP_CAP(SYS_CAP_QOS_QUE_GRP_NUM)}; \
        for (lvl_index = 0; lvl_index < CTC_QOS_SCHED_GROUP_LVL_MAX; lvl_index++) \
        {\
            if(grp_vec_index >= tmp_vec_index) \
            {\
                level = lvl_index;\
                sub_grp_id = grp_vec_index - tmp_vec_index;\
            }\
            tmp_vec_index += lvl_grp_num[lvl_index];\
        }\
    } \

/*level group id(bit[31:24] as level, bit[23:16] as lchip) ---> sub grp(per level group id, no level info)*/
#define SYS_LVL_GRP_TO_SUB_GRP(group_id, lvl, sub_grp_id) \
    { \
        lvl = (((group_id) >> 24) & 0xFF); \
        sub_grp_id = ((group_id) & 0xFFFF) - 1; \
    } \

/*sub grp(per level group id, no level info) ---> level group id(bit[31:24] as level, bit[23:16] as lchip)*/
#define SYS_SUB_GRP_TO_LVL_GRP(group_id, lvl, lchip, sub_grp_id) \
    { \
        group_id = ((((lvl)&0xFF) << 24) | (((lchip)&0xFF) << 16) | (((sub_grp_id) + 1) & 0xFFFF)); \
    } \

/*DMA sch group*/
#define SYS_DMA_SCH_GROUP_CHECK(group_id) \
    { \
         if (group_id == 1 || group_id == 0x1000001 || group_id == 0x2000001 || group_id == 0x3000001 \
             || group_id == 0x4000101 || group_id == 0x4000102 || group_id == 0x4000103 || group_id == 0x4000104 \
             || group_id == 0x4000105 || group_id == 0x4000106 || group_id == 0x4000107 || group_id == 0x4000108 \
             || group_id == 0x4000109 || group_id == 0x400010A || group_id == 0x400010B || group_id == 0x400010C \
             || group_id == 0x400010D || group_id == 0x400010E || group_id == 0x400010F || group_id == 0x4000110) \
         { \
             return CTC_E_INVALID_PARAM; \
         } \
    } \

#define SYS_CHECK_SUB_GROUP_ID(sub_group_id, level) \
    {\
        CTC_MAX_VALUE_CHECK(level, CTC_QOS_SCHED_GROUP_LVL_Q); \
        if (CTC_QOS_SCHED_GROUP_LVL_R != (level) && CTC_QOS_SCHED_GROUP_LVL_Q != (level) && DRV_IS_TMG(lchip)) \
        { \
            return CTC_E_NOT_SUPPORT; \
        } \
        if (CTC_QOS_SCHED_GROUP_LVL_Q == level) \
        { \
            CTC_MAX_VALUE_CHECK(sub_group_id, MCHIP_CAP(SYS_CAP_QOS_QUE_GRP_NUM) - 1); \
        } \
        else if(CTC_QOS_SCHED_GROUP_LVL_3 == level) \
        { \
            CTC_MAX_VALUE_CHECK(sub_group_id, MCHIP_CAP(SYS_CAP_QOS_L3_GRP_NUM) - 1); \
        } \
        else if (CTC_QOS_SCHED_GROUP_LVL_2 == level) \
        { \
            CTC_MAX_VALUE_CHECK(sub_group_id, MCHIP_CAP(SYS_CAP_QOS_L2_GRP_NUM) - 1); \
        } \
        else if (CTC_QOS_SCHED_GROUP_LVL_1 == level) \
        { \
            CTC_MAX_VALUE_CHECK(sub_group_id, MCHIP_CAP(SYS_CAP_QOS_L1_GRP_NUM) - 1); \
        } \
        else if(CTC_QOS_SCHED_GROUP_LVL_R == level) \
        { \
            CTC_MAX_VALUE_CHECK(sub_group_id, MCHIP_CAP(SYS_CAP_QOS_L0_GRP_NUM) - 1); \
        } \
    }\
/*
* queue id 8k~12k : per group 16 queue
* queue id 0~8k   :
*   1) group_mode = 1 : per group 8 queue
*   2) group_mode = 0 : per group 16 queue, group_id is even
*/
#define SYS_TMM_GROUP_ID(group_id, queue_id, group_mode) \
    { \
        if (CTC_IS_BIT_SET(queue_id, 13)) \
        {\
            group_id = (((queue_id & 0x2000) >> 3) + ((queue_id & 0x1FFF) >> 4));\
        }\
        else \
        {\
            group_id = ((queue_id >> 4) << 1 |  ((queue_id >> 3) & group_mode));\
        }\
    } \

/*get queue base form group*/
#define SYS_TMM_QUE_ID_FR_GROUP(queue_id, group_id, group_mode) \
    { \
        if (CTC_IS_BIT_SET(group_id, 10)) \
        {\
            queue_id = ((1 << 13) + ((group_id & 0xFF) << 4));\
        }\
        else \
        {\
            queue_id = (((group_id & 0x3FE) | ((group_id & 1) & group_mode)) << 3);\
        }\
    } \

#define SYS_TMM_GROUP_INDEX(group_index, group_id) \
    { \
        if (CTC_IS_BIT_SET(group_id, 10)) \
        {\
            group_index = (0x200 + (group_id & 0xff));\
        }\
        else \
        {\
            group_index = (group_id >> 1);\
        }\
    } \

#define SYS_QOS_QUE_BASE(queue_base, chan, offset, queue_base_num) {\
   if (DRV_FROM_TMM(lchip) && MCHIP_QOS(lchip)->qos_queue_get_queue_base)\
   {\
       MCHIP_QOS(lchip)->qos_queue_get_queue_base(lchip, chan, offset, &queue_base);\
   }\
   else\
   {\
       queue_base = queue_base_num;\
   }\
}

enum sys_extend_que_type_e
{
    SYS_EXTEND_QUE_TYPE_SERVICE,   /**< service queue */
    SYS_EXTEND_QUE_TYPE_BPE,       /**< bpe queue */
    SYS_EXTEND_QUE_TYPE_C2C,       /**< c2c queue */
    SYS_EXTEND_QUE_TYPE_LOGIC_PORT, /**< logic port */
    SYS_EXTEND_QUE_TYPE_MCAST,     /**< mcast queue */
    SYS_EXTEND_QUE_TYPE_ETS,     /**< ets queue */
    SYS_EXTEND_QUE_TYPE_MAX
};
typedef enum sys_extend_que_type_e sys_extend_que_type_t;

enum sys_queue_type_e
{
    SYS_QUEUE_TYPE_NORMAL,     /**< normal en queue */
    SYS_QUEUE_TYPE_EXCP,       /**< exception to cpu by DMA*/
    SYS_QUEUE_TYPE_EXTEND,     /**< extend queue */
    SYS_QUEUE_TYPE_EXCP_UC,
    SYS_QUEUE_TYPE_EUNIT,
    SYS_QUEUE_TYPE_MAX
};
typedef enum sys_queue_type_e sys_queue_type_t;

enum sys_shape_type_e
{
    SYS_SHAPE_TYPE_PORT,
    SYS_SHAPE_TYPE_QUEUE,
    SYS_SHAPE_TYPE_MAX
};
typedef enum sys_shape_type_e sys_shape_type_t;

#define SYS_QOS_SHAPE_TYPE_CHAN 0
#define SYS_QOS_SHAPE_TYPE_QUEUE 1
#define SYS_QOS_SHAPE_TYPE_MAX 2

enum sys_queue_grp_shp_cir_type_e
{
    SYS_QUEUE_GRP_SHP_CIR_TYPE_CIR_FAIL,
    SYS_QUEUE_GRP_SHP_CIR_TYPE_CIR_USER,
    SYS_QUEUE_GRP_SHP_CIR_TYPE_MAX
};
typedef enum sys_queue_grp_shp_cir_type_e sys_queue_grp_shp_cir_type_t;

enum sys_queue_spool_type_e
{
    SYS_QUEUE_PROFILE,
    SYS_QUEUE_METER_PROFILE,
    SYS_QUEUE_DROP_WTD_PROFILE,
    SYS_QUEUE_DROP_WRED_PROFILE,
    SYS_QUEUE_GROUP_PROFILE,
    SYS_QUEUE_GROUP_METER_PROFILE,
    SYS_QUEUE_FC_PROFILE,
    SYS_QUEUE_PFC_PROFILE,
    SYS_QUEUE_FC_DROP_PROFILE,
    SYS_QUEUE_PFC_DROP_PROFILE,
    SYS_QUEUE_MIN_PROFILE,
    SYS_QUEUE_ENQ_FROFILE,
    SYS_QUEUE_SPOOL_PORFILE_MAX
};
typedef enum sys_queue_spool_type_e sys_queue_spool_type_t;

enum sys_queue_fixed_mode_e
{
    SYS_QUEUE_LEGACY_MODE0,     /*8(uc+mc)+8(c2c)+1(cpuTx) mode, channel based*/
    SYS_QUEUE_LEGACY_MODE1,     /*d2:8+4(mc)ext queue+1(log) mode, channel based
                                  tm&tmm:8+1(mc)+1(log) mode, channel base*/
    SYS_QUEUE_LEGACY_MODE2,     /*only d2:8+1(mc)+1(log) mode, channel based*/
    SYS_QUEUE_FIXED_MODE,      /*8(basic UCQ)+1(span MCQ)+1(mcast MCQ)+1(c2c UCQ/MCQ)**/

    SYS_QUEUE_FIXED_MAX
};
typedef enum sys_queue_fixed_mode_e sys_queue_fixed_mode_t;

struct sys_queue_shp_grp_info_s
{
    uint32   rate;
    uint16   thrd;
    uint8    cir_type;
    uint8    bucket_sel;
};
typedef struct sys_queue_shp_grp_info_s sys_queue_shp_grp_info_t;

struct sys_group_meter_profile_s
{
    uint8  profile_id;
    uint8  rsv[3];
    sys_queue_shp_grp_info_t c_bucket[SYS_GRP_SHP_CBUCKET_NUM];
};
typedef struct sys_group_meter_profile_s sys_group_meter_profile_t;

/**
 @brief En-queue configurations.
*/
struct sys_enqueue_info_s
{
    uint8  queue_num;
    uint8  subq_num;
    uint8  queue_type;
    uint8  ucast;
    uint8  mirror;
    uint16 queue_base;
    uint16 dest_base;
    uint16 dest_num;
    uint8 stacking;
};
typedef struct sys_enqueue_info_s sys_enqueue_info_t;

struct sys_cpu_reason_s
{
    uint8    dest_type;
    uint8    user_define_mode[CTC_BOTH_DIRECTION];   /*0-none;1-DsFwd/ misc nexthop;2.alloc excep ID*/
    uint16   excp_id[CTC_BOTH_DIRECTION];
    uint32   nh_id;
    uint16   sub_queue_id;
    uint16   ref_cnt;
    uint32   dest_port;
    uint32   dest_map;
    uint32   dir          : 2,
             is_uc        : 1, /*for AT*/
             sub_idx      : 3,
             raw_dest_en  : 1,
             tcat_prof_id : 8,
             rsv          : 17;
    uint16   policer_id[2];
};
typedef struct sys_cpu_reason_s sys_cpu_reason_t;

struct sys_queue_meter_profile_s
{
    uint32 profile_id : 8,
           lchip      : 8,
           rsv        : 16;
    uint32 calc_key_len[0];

    /*data*/
    void* p_ds;

};
typedef struct sys_queue_meter_profile_s sys_queue_meter_profile_t;

struct sys_queue_shp_profile_s
{
    uint32 profile_id : 8,
           lchip      : 8,
           queue_type : 4,
           rsv        : 12;
    uint32 calc_key_len[0];

    /*data*/
    void* p_ds;

};
typedef struct sys_queue_shp_profile_s sys_queue_shp_profile_t;



struct sys_group_shp_profile_s
{
    uint8   profile_id;
    uint8   rsv;
    uint16  bucket_thrd;
    uint32  bucket_rate;
};
typedef struct sys_group_shp_profile_s sys_group_shp_profile_t;

struct sys_queue_drop_ecn_s
{
    uint8 discard;
    uint8 exception_en;
    uint8 mapped_ecn;
    uint8 rsv;
};
typedef struct sys_queue_drop_ecn_s sys_queue_drop_ecn_t;

struct sys_queue_drop_wtd_profile_s
{
    uint32 profile_id : 8,
           lchip      : 8,
           cng_num    : 4,
           rsv        : 12;
    uint32 calc_key_len[0];

    /*data*/
    void* p_ds;
};
typedef struct sys_queue_drop_wtd_profile_s sys_queue_drop_wtd_profile_t;

struct sys_queue_drop_wred_profile_s
{
    uint32 profile_id : 12,
           lchip      : 8,
           dp_id      : 4, /*for at, 0-15*/
           rsv        : 8;
    uint32 calc_key_len[0];

    /*data*/
    void* p_ds;
};
typedef struct sys_queue_drop_wred_profile_s sys_queue_drop_wred_profile_t;


struct sys_queue_guarantee_s
{
    /*key*/
    uint32 profile_id : 8,
           lchip      : 8,
           rsv        : 16;
    uint32 calc_key_len[0];

    /*data*/
    void* p_ds;
};
typedef struct sys_queue_guarantee_s sys_queue_guarantee_t;

struct sys_queue_drop_profile_s
{
    sys_queue_drop_wtd_profile_t* p_drop_wtd_profile;
    sys_queue_drop_wred_profile_t* p_drop_wred_profile;
};
typedef struct sys_queue_drop_profile_s sys_queue_drop_profile_t;

struct sys_queue_type_maping_s
{
    uint8 enq_mode : 4;
    uint8 offset   : 4;
};
typedef struct sys_queue_type_maping_s sys_queue_type_maping_t;

struct sys_queue_enq_profile_s
{
    /*key*/
    sys_queue_type_maping_t map[SYS_QUE_MAP_TYPE_MAX_NUM];
    uint8 is_mc  : 1;
    uint8 rsv : 7;

    /*data*/
    uint8 prof_id;
    uint32 calc_len[0];
};
typedef struct sys_queue_enq_profile_s sys_queue_enq_profile_t;

/*AT queue id range
BAISC UCQ+MCQ(perpp 26*2*12=624)
PP0 0    - 623
PP1 623  - 1247
PP2 1248 - 1871
PP3 1872 - 2485
PP4 2496 - 3119
PP5 3120 - 3743
PP6 3744 - 4367
PP7 4368 - 4991

DMA MCQ(128)
PP0 4992 - 5119

DMA UCQ(32)
PP0 5120 - 5152

EUINT Q(4*8=32)
PPX 5152 - 5183
*/
enum sys_queue_ofst_type_e
{
    SYS_QUE_OFST_NONE = 0,
    SYS_QUE_OFST_UC,
    SYS_QUE_OFST_MC,

    SYS_QUE_OFST_TYPE_MAX
};
typedef struct sys_queue_sub_node_s
{
    uint8 type : 2; /* refer to enum sys_queue_ofst_type_e */
    uint8 ofst : 4;
    uint8 qdrop_en : 1;
    uint8 rsv : 1;
    uint8 drop_wred_profile_id;
}sys_queue_sub_node_t;

struct sys_queue_node_s
{
    uint8  type     : 4;        /* refer to sys_queue_type_t */
    uint8  shp_en       : 1;
    uint8  sched_mode   : 1; /*uc mc sp/wdrr*/
    uint8  dp_id        : 1;
    uint8  class_prio   : 1;

    uint8  offset;      /* cos */
    uint8  pp_id    : 3;
    uint8  sub_chan : 5;

    sys_queue_sub_node_t node[SYS_QUEUE_SUB_NODE_NUM];
    uint16 queue_id;   /*D2:0~1280,TM:0-4095,TMM:0-12287;AT PP0-7 26*2*12*8(4992) + 128(DMA MCQ) + 32(DMA UCQ) + 4*32(EUINTQ)=5280*/

    uint8 drop_wtd_profile_id;
    uint8 shp_profile_id;
    uint8 meter_profile_id;
    uint8 guarantee_profile_id;
};
typedef struct sys_queue_node_s sys_queue_node_t;

struct sys_queue_group_node_s
{
    uint16   group_id;  /* ext group id; 0~63.*/
    uint16   shp_bitmap;
    uint8    chan_id;   /*0~63*/
    uint8    rsv[3];
    sys_group_shp_profile_t* p_shp_profile;
    sys_group_meter_profile_t* p_meter_profile;
};
typedef struct sys_queue_group_node_s sys_queue_group_node_t;

struct sys_qos_rate_granularity_s
{
    uint32 max_rate;        /* unit is Mbps */
    uint32 granularity;     /* unit is Kbps */
};
typedef struct sys_qos_rate_granularity_s sys_qos_rate_granularity_t;

struct sys_qos_resc_igs_port_min_s
{
    uint16 ref;
    uint16 min;
};
typedef struct sys_qos_resc_igs_port_min_s sys_qos_resc_igs_port_min_t;

struct sys_qos_resc_egs_pool_s
{
    uint8 egs_congest_level_num;
    uint8 default_profile_id;
};
typedef struct sys_qos_resc_egs_pool_s sys_qos_resc_egs_pool_t;

struct sys_qos_fc_profile_s
{
    uint32 xon;
    uint32 xoff;
    uint16 thrd;
    uint8  profile_id;
    uint8  type;/* 0:flow control profile 1:drop thrd profile*/
};
typedef struct sys_qos_fc_profile_s sys_qos_fc_profile_t;

struct sys_qos_oobfc_profile_s
{
    uint16 xon[8];
    uint16 xoff[8];
    uint16 thrd[8];
    uint32  calc_key_len[0];

    ctc_spool_index_t index;
};
typedef struct sys_qos_oobfc_profile_s sys_qos_oobfc_profile_t;

struct sys_sch_group_node_s
{
    uint32 grp_index;
    uint8 chan_valid;
    uint8 chan_id;
    uint32  parent_id;
    ctc_slist_t* p_child_list;
};
typedef struct sys_sch_group_node_s sys_sch_group_node_t;

struct sys_sch_group_child_node_s
{
    ctc_slistnode_t head;
    uint32 child_id;
};
typedef struct sys_sch_group_child_node_s sys_sch_group_child_node_t;

struct sys_sub_group_id_s
{
    uint8  group_bmp; /*bitmap,set corresponding queue_class bit when sub group id = 2*/
    uint32 group_id;  /*queue group id*/
};
typedef struct sys_sub_group_id_s sys_sub_group_id_t;

struct sys_oobfc_group_info_s
{
    uint8  mode;
    uint8  group_base; /*group base for oobfc*/
    uint8  group_num;  /*group num for oobfc*/
    uint8  port_offset;
    uint32 port_base;
    uint16 port_num;
    uint32 fcid_bmp[8];/*tmm:oobfc id*/
};
typedef struct sys_oobfc_group_info_s sys_oobfc_group_info_t;

struct sys_fcdl_info_s
{
    uint8  mode;
    uint32 timeout;
    uint8  pri_class[CTC_MAX_FCDL_DETECT_NUM]; /*higest bit indicate valid*/
    uint32 count[CTC_MAX_FCDL_DETECT_NUM];
};
typedef struct sys_fcdl_info_s sys_fcdl_info_t;

struct sys_qos_buffer_info_s
{
    DsErmPortThrdProfileUc_m port_thrd_uc; /* port uc limted & guaranteed*/
    DsErmPortLimitedThrdProfileMc_m port_limited_mc;  /* port mc limted*/
    DsErmPortGuaranteedThrdProfileMc_m port_guaranteed_mc;/* port mc guaranteed*/

    DsErmPortScThrdProfileUc_m port_sc_thrd_uc[SYS_QOS_EGRESS_SC_POOL_NUM];
    DsErmPortScGuaranteedThrdProfileMc_m port_sc_guaranteed_mc[SYS_QOS_EGRESS_SC_POOL_NUM];

    DsErmQueueThrdProfileUc_m q_thrd_uc[SYS_AT_UC_QUEUE_NUM]; /* queue uc limted & guaranteed*/
    DsErmQueueGuaranteedThrdProfileMc_m q_guaranteed_mc[SYS_AT_MC_QUEUE_NUM]; /* queue mc guaranteed*/
};
typedef struct sys_qos_buffer_info_s sys_qos_buffer_info_t;

struct sys_qos_buffer_info_tmm_s
{
    DsErmPortLimitedThrdProfile_m port_thrd; /* port limted*/
    DsErmPortGuaranteedThrdProfile_m port_guaranteed;/* port guaranteed*/

    DsErmQueueLimitedThrdProfile_m que_thrd[SYS_NORMAL_QUEUE_NUM]; /* queue limted */
    DsErmQueueGuaranteedThrdProfile_m que_guaranteed[SYS_NORMAL_QUEUE_NUM]; /* queue guaranteed*/
};
typedef struct sys_qos_buffer_info_tmm_s sys_qos_buffer_info_tmm_t;

struct sys_queue_master_s
{
    sys_cpu_reason_t  cpu_reason[CTC_PKT_CPU_REASON_MAX_COUNT];   /*AT*/
    ctc_vector_t*  queue_vec;        /*AT*/
    ctc_vector_t*  group_vec;
    ctc_vector_t*  sch_group_vec;
    ctc_vector_t*  buffer_info_vec; /*AT*/
    ctc_spool_t* p_queue_profile_pool;
    ctc_spool_t* p_queue_meter_profile_pool;
    ctc_spool_t* p_drop_wtd_profile_pool;
    ctc_spool_t* p_drop_wred_profile_pool; /*AT*/
    ctc_spool_t* p_group_profile_pool;
    ctc_spool_t* p_group_profile_meter_pool;
    ctc_spool_t* p_fc_profile_pool;
    ctc_spool_t* p_pfc_profile_pool;
    ctc_hash_t* p_port_extender_hash;
    sys_qos_fc_profile_t *p_fc_profile[SYS_MAX_CHANNEL_NUM];
    sys_qos_fc_profile_t *p_pfc_profile[SYS_MAX_CHANNEL_NUM][8];
    uint8 igs_resrc_mode[2];  /*AT*/
    uint8 egs_resrc_mode[2];  /*AT*/
    uint8 store_chan_shp_en;
    uint8 store_que_shp_en;
    uint8 monitor_drop_en;/*AT*/
    uint8 shp_pps_en     : 1,
          net_shp_pps_en : 1,
          rsv            : 6;
    uint8 have_lcpu_by_eth; /*AT*/
    uint8 queue_num_per_chanel;
    uint8 queue_num_per_extend_port;
    uint8 queue_num_per_stk_port; /*trunk member port queue mode,
                                    0: queue_num_per_chanel + 8(c2c uc&mc),
                                    1: queue_num_per_chanel + 1(c2c uc) + 1 (c2c mc)*/
    uint8 cpu_eth_chan_id;
    uint8 max_dma_rx_num;
    uint32 chan_shp_update_freq;
    uint32 que_shp_update_freq;
    sys_qos_rate_granularity_t que_shp_gran[SYS_SHP_GRAN_RANAGE_NUM]; /*AT*/
    uint8 queue_num_for_cpu_reason; /*AT*/
    uint8 opf_type_group_id;
    uint8 opf_type_tcam_index;
    uint8 opf_type_queue_shape;
    uint8 opf_type_queue_meter;
    uint8 opf_type_group_shape;
    uint8 opf_type_group_meter;
    uint8 opf_type_queue_drop_wtd;
    uint8 opf_type_queue_drop_wred;
    uint8 opf_type_resrc_fc;
    uint8 opf_type_resrc_pfc;
    uint8 opf_type_excp_index;
    uint8 opf_type_sch_group;
    sys_qos_resc_egs_pool_t egs_pool[CTC_QOS_EGS_RESRC_POOL_MAX];
    uint8 enq_mode;  /* d2: 0: 8(uc+mc)+8(c2c)+1(cpu) mode, channel based;
                            1: 8+4(mc)ext queue+1(log)+1(cpu) mode, channel based;
                            2: 8(uc+mc)+8(c2c)+1(log)+1(cpu) mode, channel based;
                    tm&tmm: 0: 8(uc+mc)+8(c2c)+1(cpu) mode, channel based;
                            1: 8+1(mc)+8(c2c)+1(log)+1(cpu) mode, channel based;
                            2: 8(uc+mc)+8(c2c)+1(log)+1(cpu) mode, channel based;*/
    uint8 opf_type_resrc_fc_dropthrd;
    uint8 opf_type_resrc_pfc_dropthrd;
    ctc_spool_t* p_fc_dropthrd_profile_pool;
    ctc_spool_t* p_pfc_dropthrd_profile_pool;
    sys_qos_fc_profile_t *p_dropthrd_fc_profile[SYS_MAX_CHANNEL_NUM];
    sys_qos_fc_profile_t *p_dropthrd_pfc_profile[SYS_MAX_CHANNEL_NUM][8];
    uint8 resrc_check_mode; /* 1:DISCRETE  0:CONTINUOUS */
    ctc_hash_t* p_service_hash;
    ctc_hash_t* p_logicport_service_hash;
    uint8 service_queue_mode; /* 1:service id+dstport  0:logic src port+dstport 2:logic src port or nexthop ptr*/
    uint8 opf_type_queue_guarantee;
    ctc_spool_t* p_queue_guarantee_pool;
    sys_sub_group_id_t group_id_ets[SYS_MAX_CHANNEL_NUM];
    uint32 l3_group_id_bpe[SYS_MAX_CHANNEL_NUM];
    ctc_spool_t* p_oobfc_profile_pool;
    sys_qos_oobfc_profile_t *p_oobfc_profile[SYS_MAX_CHANNEL_NUM];/*for egress oobfc request*/
    sys_oobfc_group_info_t oobfc_group_info;
    sal_timer_t* p_recover_timer;
    uint32 fcdl_action;    /* refer to ctc_qos_fcdl_action_t */
    sys_fcdl_info_t* fcdl_info;   /*AT*/
    uint8* p_chan_guar_profileid; /*egress chan guarantee thrd*/

    ctc_spool_t* enq_prof_spool;
    uint16 enq_prof_bmp; /*enq profile id bitmap*/
};
typedef struct sys_queue_master_s sys_queue_master_t;

struct sys_extend_que_node_s
{
    uint8  type;     /** sys_extend_que_type_t */
    uint8  lchip;
    uint16 service_id;
    uint16 lport;
    uint8  channel;
    uint8  dir;
    uint16 logic_src_port;
    uint16 rsv1;

    uint16 logic_dst_port;
    uint16 queue_id;
    uint32 group_is_alloc : 8,
           rsv2           : 24;
    uint16 group_id;
    uint16 key_index;
    uint32 nexthop_ptr;
};
typedef struct sys_extend_que_node_s sys_extend_que_node_t;

struct sys_qos_logicport_service_s
{
    uint16  logic_src_port;
    uint16  service_id;
};
typedef struct sys_qos_logicport_service_s sys_qos_logicport_service_t;

struct sys_qos_logicport_s
{
    ctc_slistnode_t head;
    uint16 logic_port;
};
typedef struct sys_qos_logicport_s sys_qos_logicport_t;

struct sys_qos_destport_s
{
    ctc_slistnode_t head;
    uint8 lchip;
    uint16 lport;          /*dest port list*/
};
typedef struct sys_qos_destport_s sys_qos_destport_t;

struct sys_service_node_s
{
    uint16 service_id;               /*service id*/
    uint16 rsv;
    ctc_slist_t* p_logic_port_list; /*source logic port list*/
    ctc_slist_t* p_dest_port_list;  /*dest port list*/
};
typedef struct sys_service_node_s sys_service_node_t;

enum sys_qos_service_mode_s
{
    SYS_QUEUE_SERVICE_MODE_NONE,
    SYS_QUEUE_SERVICE_MODE_SERVICE_ID,
    SYS_QUEUE_SERVICE_MODE_LOGIC_PORT,
    SYS_QUEUE_SERVICE_MODE_NH_OFFSET,
    SYS_QUEUE_SERVICE_MODE_MAX
};
typedef enum sys_qos_service_mode_s sys_qos_service_mode_t;


/****************************** queue drop ******************************/
#define SYS_DROP_COUNT_GE       0x38
#define SYS_DROP_DELTA_GE       0x4
#define SYS_DROP_COUNT_XGE      0x40
#define SYS_DROP_DELTA_XGE      0x10

#define SYS_DEFAULT_TAIL_DROP_PROFILE 0
#define SYS_DEFAULT_GRP_DROP_PROFILE  0

/****************************** policer ******************************/
#define SYS_QOS_POLICER_HASH_TBL_SIZE         512
#define SYS_QOS_POLICER_HASH_BLOCK_SIZE       ((MCHIP_CAP(SYS_CAP_QOS_POLICER_POLICER_NUM) + MCHIP_CAP(SYS_CAP_QOS_POLICER_SVC_POLICER_NUM)) / SYS_HASH_SIZE_COMPRESS_RATE_8 / SYS_QOS_POLICER_HASH_TBL_SIZE)

#define SYS_QOS_POLICER_PROF_HASH_TBL_SIZE    16
#define SYS_QOS_POLICER_PROF_HASH_BLOCK_SIZE  (MCHIP_CAP(SYS_CAP_QOS_POLICER_PROFILE_NUM) / SYS_QOS_POLICER_PROF_HASH_TBL_SIZE)

#define SYS_QOS_POLICER_COPP_PROF_HASH_TBL_SIZE    2
#define SYS_QOS_POLICER_COPP_PROF_HASH_BLOCK_SIZE  (MCHIP_CAP(SYS_CAP_QOS_POLICER_COPP_PROFILE_NUM) / SYS_QOS_POLICER_COPP_PROF_HASH_TBL_SIZE)

#define SYS_QOS_POLICER_MFP_PROF_HASH_TBL_SIZE    4
#define SYS_QOS_POLICER_MFP_PROF_HASH_BLOCK_SIZE  (MCHIP_CAP(SYS_CAP_QOS_POLICER_MFP_PROFILE_NUM) / SYS_QOS_POLICER_MFP_PROF_HASH_TBL_SIZE)

#define SYS_QOS_POLICER_ACTION_PROF_HASH_TBL_SIZE    4
#define SYS_QOS_POLICER_ACTION_PROF_HASH_BLOCK_SIZE  (MCHIP_CAP(SYS_CAP_QOS_POLICER_ACTION_PROFILE_NUM) / SYS_QOS_POLICER_ACTION_PROF_HASH_TBL_SIZE)

#define SYS_QOS_POLICER_SVC_PROF_HASH_TBL_SIZE    16
#define SYS_QOS_POLICER_SVC_PROF_HASH_BLOCK_SIZE  (MCHIP_CAP(SYS_CAP_QOS_POLICER_SVC_PROFILE_NUM) / SYS_QOS_POLICER_SVC_PROF_HASH_TBL_SIZE)

#define SYS_QOS_POLICER_SVC_ACTION_PROF_HASH_TBL_SIZE    4
#define SYS_QOS_POLICER_SVC_ACTION_PROF_HASH_BLOCK_SIZE  (MCHIP_CAP(SYS_CAP_QOS_POLICER_SVC_ACTION_PROFILE_NUM) / SYS_QOS_POLICER_SVC_ACTION_PROF_HASH_TBL_SIZE)

#define SYS_QOS_POLICER_MAX_COUNT     (0xFFF<<0xD)
#define SYS_QOS_POLICER_SVC_MAX_COUNT 0x7FFFFF
#define SYS_QOS_MFP_MAX_COUNT     67108
#define SYS_QOS_MFP_MAX_RATE      67108856
#define SYS_QOS_VLAN_RESERVE_NUM     4

/* get port policer offset */
#define SYS_QOS_PORT_POLICER_INDEX(lport, dir, phb_offset) \
    ((lport & 0xff) + (phb_offset) \
    + p_usw_qos_policer_master[lchip]->port_policer_base[dir])

#define SYS_QOS_POLICER_DBG_OUT(level, FMT, ...) \
    do { \
        CTC_DEBUG_OUT(qos, policer, QOS_PLC_SYS, level, FMT, ##__VA_ARGS__); \
    } while (0);

/* max port policer num in both direction */
enum sys_policer_cnt_s
{
    SYS_POLICER_CNT_PORT_POLICER,
    SYS_POLICER_CNT_FLOW_POLICER,
    SYS_POLICER_CNT_VLAN_POLICER,
    SYS_POLICER_CNT_SVC_POLICER,
    SYS_POLICER_CNT_CHAN_POLICER,
    SYS_POLICER_CNT_MAX
};
typedef enum sys_policer_cnt_s sys_policer_cnt_t;

enum sys_qos_policer_level_e
{
    SYS_QOS_POLICER_IPE_POLICING_0,
    SYS_QOS_POLICER_IPE_POLICING_1,
    SYS_QOS_POLICER_EPE_POLICING_0,
    SYS_QOS_POLICER_EPE_POLICING_1,
    SYS_QOS_POLICER_LEVEL_MAX
};
typedef enum sys_qos_policer_level_e  sys_qos_policer_level_t;

  /**
 @brief  qos prof entry data structure
*/
struct sys_qos_policer_profile_s
{
    uint8   is_bucketY;
    uint8   policer_lvl;

    uint16  threshold;
    uint8   thresholdShift;

    uint8   rateShift;
    uint16  rate;
    uint8   rateFrac;
    uint8   rateMaxShift;
    uint16  rateMax;

    uint8   profile_id;
    uint8   rsv[3];
};
typedef struct sys_qos_policer_profile_s sys_qos_policer_profile_t;

/**
 @brief  qos policer action data structure
*/
struct sys_qos_policer_action_s
{
    uint32 flag;                /*refer to ctc_qos_policer_action_flag_t*/
    uint8  dir;                 /*refer to ctc_direction_t*/
    uint8  prio_green;
    uint8  prio_yellow;
    uint8  prio_red;
    uint8  discard_green;
    uint8  discard_yellow;
    uint8  discard_red;
    uint8  profile_id;
};
typedef struct sys_qos_policer_action_s sys_qos_policer_action_t;

struct sys_qos_policer_copp_profile_s
{
    uint8   is_bucketY;
    uint16  threshold;
    uint8   thresholdShift;

    uint16  rate;
    uint8   rateShift;
    uint8   rateFrac;

    uint8   policer_lvl;
    uint8   rsv0[3];

    uint8   profile_id;
    uint8   rsv1[3];
};
typedef struct sys_qos_policer_copp_profile_s sys_qos_policer_copp_profile_t;


/**
 @brief  qos svc prof entry data structure
*/
struct sys_qos_policer_svc_profile_s
{
    uint32  rateX;
    uint32  rateY;

    uint32  thresholdX;
    uint32  thresholdY;
    uint32  calc_key_len[0];

    ctc_spool_index_t index;

};
typedef struct sys_qos_policer_svc_profile_s sys_qos_policer_svc_profile_t;

struct sys_qos_policer_normal_profile_s
{
    sys_qos_policer_profile_t* p_sys_profileX;
    sys_qos_policer_profile_t* p_sys_profileY;
    sys_qos_policer_action_t*  p_sys_action_profile;
};
typedef struct sys_qos_policer_normal_profile_s sys_qos_policer_normal_profile_t;

struct sys_qos_policer_s
{
    uint8  type; /*ctc_qos_policer_type_t*/
    uint8  dir;   /*ctc_direction_t */
    uint16 id;

    uint32 level                  : 2,
           split_en               : 1,
           hbwp_en                : 1,
           is_pps                 : 1,
           cos_index              : 3,
           sf_en                  : 1,
           cf_total_dis           : 1,
           cf_en                  : 1,
           is_color_aware         : 1,
           use_l3_length          : 1,
           drop_color             : 2,
           stats_en               : 1,
           stats_mode             : 2,
           stats_num              : 3,
           color_merge_mode       : 2,
           storm_base             : 3,
           storm_discarded_to_cpu : 1,
           storm_mode             : 3,
           glb_policer            : 1,
           rsv0                   : 1;

    uint32 policer_lvl                  : 2,
           stats_ptr_alloc              : 1,
           prio_green                   : 4,
           prio_yellow                  : 4,
           prio_red                     : 4,
           is_installed                 : 1,
           gran                         : 16;

    uint32 policer_mode          : 8,
           entry_size            : 8,
           sys_policer_type      : 8,     /*refer to sys_qos_policer_type_t*/
           max_level             : 3,
           rsv1                  : 5;
    uint32 flag;                /*refer to ctc_qos_policer_action_flag_t*/


    uint32 cir;
    uint32 cbs;

    uint32 pir;
    uint32 pbs;

    uint32 cir_max;
    uint32 pir_max;    /*when svc policer is used as stormctl, means storm_thrd*/

    uint16 cos_bitmap; /*bitmap of hbwp enable*/
    uint16 policer_ptr;
    uint32* stats_ptr;

    void** pp_policer_profile; /*use for policer profile :
                                 which sys_policer_type is SYS_QOS_POLICER_TYPE_COPP: refer to sys_qos_policer_copp_profile_t,
                                 which sys_policer_type is SYS_QOS_POLICER_TYPE_SVC : refer to sys_qos_policer_svc_profile_t,
                                 else  refer to sys_qos_policer_normal_profile_t*/
};
typedef struct sys_qos_policer_s sys_qos_policer_t;

struct sys_qos_policer_action_profile_s
{
    uint8 decX;
    uint8 decY;
    uint8 newColor;
};
typedef struct sys_qos_policer_action_profile_s sys_qos_policer_action_profile_t;

struct sys_qos_policer_share_profile_s
{
    uint8 dec0X;
    uint8 dec0Y;
    uint8 dec1X;
    uint8 dec1Y;
    uint8 newColor;
};
typedef struct sys_qos_policer_share_profile_s sys_qos_policer_share_profile_t;

struct sys_qos_policer_master_s
{
    ctc_hash_t* p_policer_hash;
    ctc_spool_t* p_profile_pool;
    ctc_spool_t* p_svc_profile_pool;
    ctc_spool_t* p_action_profile_pool;
    ctc_spool_t* p_copp_profile_pool;

    uint16  glb_policer_num[SYS_QOS_POLICER_LEVEL_MAX];
    uint16  port_policer_base[CTC_BOTH_DIRECTION];
    uint16  vlan_policer_base[CTC_BOTH_DIRECTION];
    uint16  group_policer_base[CTC_BOTH_DIRECTION];
    uint16  svc_policer_base;
    uint8   max_cos_level;
    uint8   opf_type_policer_config;
    uint8   opf_type_ipe_policer0_profile;
    uint8   opf_type_ipe_policer1_profile;
    uint8   opf_type_epe_policer0_profile;
    uint8   opf_type_epe_policer1_profile;
    uint8   opf_type_copp_config;
    uint8   opf_type_copp_profile;
    uint8   opf_type_epe_copp_profile;
    uint8   opf_type_mfp_profile;
    uint8   opf_type_action_profile;
    uint8   opf_type_svc_config;
    uint16  policer_count[SYS_POLICER_CNT_MAX];
    uint32  policer_update_freq;
    uint32  copp_update_freq;
    uint32  mfp_update_freq;
    uint32  svc_update_freq;
    uint16 igs_macro_policer_num;
    uint16 egs_macro_policer_num;
    uint16 ingress_vlan_policer_num;
    uint16 egress_vlan_policer_num;
    uint8  policer_merge_mode;
    uint8  policer_svc_mode;
    uint64 *policer_svc_stats;
};
typedef struct sys_qos_policer_master_s sys_qos_policer_master_t;

extern sys_qos_policer_master_t* p_usw_qos_policer_master[CTC_MAX_LOCAL_CHIP_NUM_PP];

typedef int32 (*SYS_QOS_TRAVERSE_FUNC)(uint8 lchip, sys_traverse_t* data);
typedef int32 (*SYS_QOS_API_INIT_FUNC)(uint8 lchip, void* p_glb_parm);
typedef int32 (*SYS_QOS_API_DEINIT_FUNC)(uint8 lchip);
typedef int32 (*SYS_QOS_API_GET_CHAN_BY_PORT_FUNC)(uint8 lchip, uint32 gport, uint16 *channel);
typedef int32 (*SYS_QOS_API_ADD_PORT_TO_CHAN_FUNC)(uint8 lchip, uint16 lport, uint16 channel, uint8 is_pp);
typedef int32 (*SYS_QOS_API_REMOVE_PORT_FROM_CHAN_FUNC)(uint8 lchip, uint16 lport, uint16 channel);
typedef int32 (*SYS_QOS_API_ADD_EXT_PORT_TO_CHAN_FUNC)(uint8 lchip, uint16 lport, uint32 gport);
typedef int32 (*SYS_QOS_API_REMOVE_EXT_PORT_FROM_CHAN_FUNC)(uint8 lchip, uint16 lport, uint32 gport);
typedef int32 (*SYS_QOS_API_ADD_MCAST_QUEUE_TO_CHAN_FUNC)(uint8 lchip, uint16 lport, uint8 channel, uint8 flag);
typedef int32 (*SYS_QOS_API_ADD_MCAST_QUE_TO_CHAN_FUNC)(uint8 lchip, uint16 lport, uint8 channel, uint8 flag);
typedef int32 (*SYS_QOS_API_REMOVE_MCAST_QUE_FROM_CHAN_FUNC)(uint8 lchip, uint16 lport, uint8 channel);
typedef int32 (*SYS_QOS_API_SET_MC_QUE_HIGH_PRI_EN_FUNC)(uint8 lchip);
typedef int32 (*SYS_QOS_API_QUE_SET_PORT_DROP_EN_FUNC)(uint8 lchip, uint32 chan_id, bool enable, void* p_drop_param);
typedef int32 (*SYS_QOS_API_QUE_GET_PROFILE_FROM_HW_FUNC)(uint8 lchip, uint32 gport, sys_qos_shape_profile_t* p_shp_profile);
typedef int32 (*SYS_QOS_API_SET_DMA_CHAN_DROP_EN_FUNC)(uint8 lchip, bool enable);
typedef int32 (*SYS_QOS_API_SET_AQMSCAN_HIGH_PRI_EN_FUNC)(uint8 lchip, bool enable);
typedef int32 (*SYS_QOS_API_QUE_GET_PORT_DEPTH_FUNC)(uint8 lchip, uint32 gport, uint32* p_depth);
typedef int32 (*SYS_QOS_API_QUE_ADD_FOR_STACKING_FUNC)(uint8 lchip, uint32 gport);
typedef int32 (*SYS_QOS_API_QUE_REMOVE_FOR_STACKING_FUNC)(uint8 lchip, uint32 gport);
typedef int32 (*SYS_QOS_API_BIND_SERVICE_LOGIC_DSTPORT_FUNC)(uint8 lchip, uint16 service_id, uint16 logic_dst_port, uint32 gport,uint32 nexthop_ptr);
typedef int32 (*SYS_QOS_API_UNBIND_SERVICE_LOGIC_DSTPORT_FUNC)(uint8 lchip, uint16 service_id, uint16 logic_dst_port, uint32 gport);
typedef int32 (*SYS_QOS_API_BIND_SERVICE_LOGIC_SRCPORT_FUNC)(uint8 lchip, uint16 service_id, uint16 logic_port);
typedef int32 (*SYS_QOS_API_UNBIND_SERVICE_LOGIC_SRCPORT_FUNC)(uint8 lchip, uint16 service_id, uint16 logic_port);
typedef int32 (*SYS_QOS_API_SET_DROP_RESRC_CHK_MODE_FUNC)(uint8 lchip, uint8 mode);
typedef int32 (*SYS_QOS_API_SET_FC_DEFAULT_PROFILE_FUNC)(uint8 lchip, uint32 gport);
typedef int32 (*SYS_QOS_API_QUE_GET_QUE_ID_FUNC)(uint8 lchip, ctc_qos_queue_id_t* p_queue,uint16* queue_id);
typedef int32 (*SYS_QOS_API_QUE_ID_GET_QUE_FUNC)(uint8 lchip, ctc_qos_queue_id_t* p_queue,uint16 queue_id);
typedef int32 (*SYS_QOS_API_GET_CHAN_BY_QUE_ID_FUNC)(uint8 lchip, uint16 queue_id, uint16 *channel);
typedef int32 (*SYS_QOS_API_QUE_DUMP_FUNC)(uint8 lchip, uint16 start, uint16 end, uint8 detail);
typedef int32 (*SYS_QOS_API_GROUP_DUMP_FUNC)(uint8 lchip, uint32 start, uint32 end, uint8 detail);
typedef int32 (*SYS_QOS_API_PORT_DUMP_FUNC)(uint8 lchip, uint32 start, uint32 end, uint8 detail);
typedef int32 (*SYS_QOS_API_SERVICE_DUMP_FUNC)(uint8 lchip, uint16 service_id, uint32 gport);
typedef int32 (*SYS_QOS_API_DUMP_STATUS_FUNC)(uint8 lchip);
typedef int32 (*SYS_QOS_API_SET_SHAPE_FUNC)(uint8 lchip, ctc_qos_shape_t* p_shape);
typedef int32 (*SYS_QOS_API_GET_SHAPE_FUNC)(uint8 lchip, ctc_qos_shape_t* p_shape);
typedef int32 (*SYS_QOS_API_SET_SCHED_FUNC)(uint8 lchip, ctc_qos_sched_t* p_sched);
typedef int32 (*SYS_QOS_API_GET_SCHED_FUNC)(uint8 lchip, ctc_qos_sched_t* p_sched);
typedef int32 (*SYS_QOS_API_SET_GLB_CFG_FUNC)(uint8 lchip, ctc_qos_glb_cfg_t* p_glb_cfg, sys_nh_info_dsnh_t* p_nhinfo);
typedef int32 (*SYS_QOS_API_GET_GLB_CFG_FUNC)(uint8 lchip, ctc_qos_glb_cfg_t* p_glb_cfg);
typedef int32 (*SYS_QOS_API_SET_QUE_FUNC)(uint8 lchip, ctc_qos_queue_cfg_t* p_que_cfg, sys_cpu_reason_dest_info_t* p_dest_info);
typedef int32 (*SYS_QOS_API_GET_QUE_FUNC)(uint8 lchip, ctc_qos_queue_cfg_t* p_que_cfg);
typedef int32 (*SYS_QOS_API_SET_DROP_FUNC)(uint8 lchip, ctc_qos_drop_t* p_drop);
typedef int32 (*SYS_QOS_API_GET_DROP_FUNC)(uint8 lchip, ctc_qos_drop_t* p_drop);
typedef int32 (*SYS_QOS_API_SET_RESRC_FUNC)(uint8 lchip, ctc_qos_resrc_t* p_resrc);
typedef int32 (*SYS_QOS_API_GET_RESRC_FUNC)(uint8 lchip, ctc_qos_resrc_t* p_resrc);
typedef int32 (*SYS_QOS_API_QUERY_POOL_STATS_FUNC)(uint8 lchip, ctc_qos_resrc_pool_stats_t* p_stats);
typedef int32 (*SYS_QOS_API_QUERY_QUE_STATS_FUNC)(uint8 lchip, ctc_qos_queue_stats_t* p_queue_stats);
typedef int32 (*SYS_QOS_API_CLEAR_QUE_STATS_FUNC)(uint8 lchip, ctc_qos_queue_stats_t* p_queue_stats);
typedef int32 (*SYS_QOS_API_QUERY_STATS_FUNC)(uint8 lchip, ctc_qos_stats_type_t type, void* p_queue_stats);
typedef int32 (*SYS_QOS_API_CLEAR_STATS_FUNC)(uint8 lchip, ctc_qos_stats_type_t type, void* p_queue_stats);
typedef int32 (*SYS_QOS_API_SET_EGS_RESRC_GUARANTEE_FUNC)(uint8 lchip, uint8 enable);
typedef int32 (*SYS_QOS_API_SET_PORT_DYNAMIC_SWITCH_FUNC)(uint8 lchip, uint16 lport, uint8 index);
typedef int32 (*SYS_QOS_API_SET_MONITOR_DROP_DISCARD_FUNC)(uint8 lchip, uint8 enable);

typedef int32 (*SYS_QOS_API_GET_CHAN_BY_SUB_CHAN_FUNC)(uint8 lchip, uint8 dp_id, uint8 sub_chan, uint16 *chan);
typedef int32 (*SYS_QOS_API_TRAVERSE_QUEUE_NODE_FUNC)(uint8 lchip, uint16 lport,
                                                      SYS_QOS_TRAVERSE_FUNC fn,
                                                      void* user_data);

typedef enum sys_qos_api_cb_type_e
{
    SYS_QOS_API_INIT,
    SYS_QOS_API_DEINIT,
    SYS_QOS_API_GET_CHAN_BY_PORT,
    SYS_QOS_API_ADD_PORT_TO_CHAN,
    SYS_QOS_API_REMOVE_PORT_FROM_CHAN,
    SYS_QOS_API_ADD_EXT_PORT_TO_CHAN,
    SYS_QOS_API_REMOVE_EXT_PORT_FROM_CHAN,
    SYS_QOS_API_ADD_MCAST_QUE_TO_CHAN,
    SYS_QOS_API_REMOVE_MCAST_QUE_FROM_CHAN,
    SYS_QOS_API_SET_MC_QUE_HIGH_PRI_EN,
    SYS_QOS_API_QUE_SET_PORT_DROP_EN,
    SYS_QOS_API_QUE_GET_PROFILE_FROM_HW,
    SYS_QOS_API_SET_DMA_CHAN_DROP_EN,
    SYS_QOS_API_SET_AQMSCAN_HIGH_PRI_EN,
    SYS_QOS_API_QUE_GET_PORT_DEPTH,
    SYS_QOS_API_QUE_ADD_FOR_STACKING,
    SYS_QOS_API_QUE_REMOVE_FOR_STACKING,
    SYS_QOS_API_BIND_SERVICE_LOGIC_DSTPORT,
    SYS_QOS_API_UNBIND_SERVICE_LOGIC_DSTPORT,
    SYS_QOS_API_BIND_SERVICE_LOGIC_SRCPORT,
    SYS_QOS_API_UNBIND_SERVICE_LOGIC_SRCPORT,
    SYS_QOS_API_SET_DROP_RESRC_CHK_MODE,
    SYS_QOS_API_SET_FC_DEFAULT_PROFILE,
    SYS_QOS_API_QUE_GET_QUE_ID,
    SYS_QOS_API_QUE_ID_GET_QUE,
    SYS_QOS_API_GET_CHAN_BY_QUE_ID,
    SYS_QOS_API_QUE_DUMP,
    SYS_QOS_API_GROUP_DUMP,
    SYS_QOS_API_PORT_DUMP,
    SYS_QOS_API_SERVICE_DUMP,
    SYS_QOS_API_DUMP_STATUS,
    SYS_QOS_API_SET_SHAPE,
    SYS_QOS_API_GET_SHAPE,
    SYS_QOS_API_SET_SCHED,
    SYS_QOS_API_GET_SCHED,
    SYS_QOS_API_SET_GLB_CFG,
    SYS_QOS_API_GET_GLB_CFG,
    SYS_QOS_API_SET_QUE,
    SYS_QOS_API_GET_QUE,
    SYS_QOS_API_SET_DROP,
    SYS_QOS_API_GET_DROP,
    SYS_QOS_API_SET_RESRC,
    SYS_QOS_API_GET_RESRC,
    SYS_QOS_API_QUERY_POOL_STATS,
    SYS_QOS_API_QUERY_QUE_STATS,
    SYS_QOS_API_CLEAR_QUE_STATS,
    SYS_QOS_API_GET_CHAN_BY_SUB_CHAN,
    SYS_QOS_API_QUERY_STATS,
    SYS_QOS_API_CLEAR_STATS,
    SYS_QOS_API_SET_EGS_RESRC_GUARANTEE,
    SYS_QOS_API_TRAVERSE_QUEUE_NODE,
    SYS_QOS_API_SET_PORT_DYNAMIC_SWITCH,
    SYS_QOS_API_SET_MONITOR_DROP_DISCARD,

    SYS_QOS_API_CB_TYPE_MAX
}sys_qos_api_cb_type_t;

struct sys_qos_master_s
{
    sal_mutex_t* p_qos_mutex;
    void* api_cb[SYS_QOS_API_CB_TYPE_MAX];
};
typedef struct sys_qos_master_s sys_qos_master_t;

#define SYS_QOS_API_CB(ERROR_CODE, TYPE, ...) \
    ((p_usw_qos_master[lchip]->api_cb[TYPE] == NULL) ? (ERROR_CODE) : ((TYPE##_FUNC)(p_usw_qos_master[lchip]->api_cb[TYPE]))(__VA_ARGS__))

/*********************************************************************
*
* Function Declaration
*
*********************************************************************/
/****************************** qos class ******************************/
extern int32
sys_usw_qos_domain_map_set(uint8 lchip, ctc_qos_domain_map_t* p_domain_map);
extern int32
sys_usw_qos_domain_map_get(uint8 lchip, ctc_qos_domain_map_t* p_domain_map);
extern int32
sys_usw_qos_table_map_set(uint8 lchip, ctc_qos_table_map_t* p_domain_map);
extern int32
sys_usw_qos_table_map_get(uint8 lchip, ctc_qos_table_map_t* p_domain_map);
extern int32
sys_usw_qos_obm_map_set(uint8 lchip, ctc_qos_obm_map_t* p_obm_map);
extern int32
sys_usw_qos_obm_map_get(uint8 lchip, ctc_qos_obm_map_t* p_obm_map);
extern int32
_sys_usw_qos_domain_map_default(uint8 lchip);
extern int32
_sys_usw_qos_domain_map_dump(uint8 lchip, uint8 domain, uint8 type);
extern int32
_sys_usw_qos_table_map_dump(uint8 lchip, uint8 table_map_id, uint8 type);
extern int32
sys_usw_qos_class_init(uint8 lchip);
extern int32
sys_usw_qos_class_deinit(uint8 lchip);

/****************************** qos policer ******************************/
extern int32
sys_usw_qos_policer_set(uint8 lchip, ctc_qos_policer_t* p_policer);
extern int32
sys_usw_qos_policer_get(uint8 lchip, ctc_qos_policer_t* p_policer);
extern int32
sys_usw_qos_lookup_policer(uint8 lchip, sys_qos_policer_t** p_sys_policer_get, uint8 sys_policer_type, uint8 dir, uint16 policer_id);
extern int32
_sys_usw_qos_policer_group_bind(uint8 lchip,sys_qos_policer_group_info_t* p_policer_group_info);
extern int32
_sys_usw_qos_policer_group_unbind(uint8 lchip,sys_qos_policer_group_info_t* p_policer_group_info);
extern int32
_sys_usw_qos_policer_group_check_bind(uint8 lchip, sys_qos_policer_group_info_t* p_policer_group_info);
extern int32
_sys_usw_qos_policer_svc_mode_check(uint8 lchip, uint8 op, uint8 is_stmctl, uint8* sup);
extern int32
_sys_usw_qos_policer_svc_stmctl_set_cfg(uint8 lchip, uint8 mstorm_ctl_mode, uint8 ipg_en);
extern int32
_sys_usw_qos_policer_svc_stmctl_set(uint8 lchip, sys_qos_api_svc_stmctl_cfg_t* svc_stmctl_cfg);
extern int32
_sys_usw_qos_policer_svc_stmctl_get(uint8 lchip, sys_qos_api_svc_stmctl_cfg_t* svc_stmctl_cfg);
extern int32
_sys_usw_qos_policer_alloc_and_install(uint8 lchip, sys_qos_policer_param_t* p_policer_param);
extern int32
_sys_usw_qos_policer_free_and_uninstall(uint8 lchip, sys_qos_policer_param_t* p_policer_param);
extern int32
_sys_usw_qos_policer_map_token_rate_user_to_hw(uint8 lchip, uint8 is_pps, uint32 user_rate,
                                                    uint32 *hw_rate, uint16 bit_with, uint32 gran, uint32 upd_freq );
extern int32
_sys_usw_qos_policer_map_token_rate_hw_to_user(uint8 lchip, uint8 is_pps,
                                                                     uint32 hw_rate,uint32 *user_rate, uint32 upd_freq);
extern int32
sys_usw_qos_policer_copp_alloc(uint8 lchip, uint32 rate, uint32 threshold,
                                               uint8 pps_mode, uint8* p_policer_ptr);
extern int32
sys_usw_qos_policer_copp_free(uint8 lchip, uint8 policer_ptr);
extern int32
sys_usw_qos_policer_mfp_get_profile(uint8 lchip, uint8 profile_id, uint32* p_rate, uint32* p_threshold);
extern int32
sys_usw_qos_set_policer_update_enable(uint8 lchip, uint8 enable);
extern int32
sys_usw_qos_set_phb(uint8 lchip, ctc_qos_phb_map_t *p_phb_map);
extern int32
sys_usw_qos_get_phb(uint8 lchip, ctc_qos_phb_map_t *p_phb_map);
extern int32
sys_usw_qos_set_policer_flow_first(uint8 lchip, uint8 dir, uint8 enable);
extern int32
sys_usw_qos_set_policer_ipg_enable(uint8 lchip, uint8 enable);
extern int32
sys_usw_qos_policer_stats_query(uint8 lchip, ctc_qos_policer_stats_t* p_stats);
extern int32
sys_usw_qos_policer_stats_clear(uint8 lchip, ctc_qos_policer_stats_t* p_stats);
extern int32
sys_usw_qos_set_policer_level_select(uint8 lchip, ctc_qos_policer_level_select_t policer_level);
extern int32
sys_usw_qos_get_policer_level_select(uint8 lchip, ctc_qos_policer_level_select_t* policer_level);
extern int32
_sys_usw_qos_policer_dump(uint8 type, uint8 dir, uint8 lchip, uint32 start, uint32 end, uint8 detail);
extern int32
sys_usw_qos_policer_wb_sync(uint8 lchip, uint32 appid, ctc_wb_data_t *p_wb_data);
extern int32
sys_usw_qos_policer_wb_restore(uint8 lchip, ctc_wb_query_t *p_wb_query);
extern int32
sys_usw_qos_policer_dump_db(uint8 lchip, sal_file_t p_f,ctc_global_dump_db_t* p_dump_param);
extern int32
sys_usw_qos_policer_init(uint8 lchip, ctc_qos_global_cfg_t *p_glb_parm);
extern int32
sys_usw_qos_policer_deinit(uint8 lchip);
extern int32
_sys_usw_qos_policer_ingress_vlan_get(uint8 lchip, uint16* ingress_vlan_policer_num);
extern int32
_sys_usw_qos_policer_egress_vlan_get(uint8 lchip, uint16* egress_vlan_policer_num);
/****************************** queue enq ******************************/
extern sys_extend_que_node_t*
sys_usw_port_extender_lookup(uint8 lchip, sys_extend_que_node_t* p_node);
extern int32
sys_usw_qos_get_mux_port_enable(uint8 lchip, uint32 gport, uint8* enable);
extern int32
sys_usw_queue_get_queue_id(uint8 lchip, ctc_qos_queue_id_t* p_queue, uint16* queue_id);
extern int32
sys_usw_queue_id_get_queue(uint8 lchip, ctc_qos_queue_id_t* p_queue,uint16 queue_id);
extern uint8
_sys_usw_queue_get_enq_mode(uint8 lchip);
extern int32
sys_usw_queue_get_queue_type_by_queue_id(uint8 lchip, uint16 queue_id, uint8 *queue_type);
extern int32
sys_usw_get_channel_by_queue_id(uint8 lchip, uint16 queue_id, uint16 *channel);
extern int32
sys_usw_queue_get_enqueue_info(uint8 lchip, uint16* port_num, uint8 *destid_mode);
extern int32
sys_usw_qos_queue_set(uint8 lchip, ctc_qos_queue_cfg_t* p_que_cfg, sys_cpu_reason_dest_info_t* p_dest_info);
extern int32
sys_usw_qos_queue_get(uint8 lchip, ctc_qos_queue_cfg_t* p_que_cfg);
extern int32
sys_usw_set_local_switch_enable(uint8 lchip, bool enable);
extern int32
sys_usw_get_local_switch_enable(uint8 lchip, bool* p_enable);

extern int32
_sys_usw_qos_add_extend_port_to_channel(uint8 lchip, uint16 lport, uint32 gport);
extern int32
_sys_usw_qos_remove_extend_port_to_channel(uint8 lchip, uint16 lport, uint32 gport);
extern int32
_sys_usw_qos_add_mcast_queue_to_channel(uint8 lchip, uint16 lport, uint8 channel, uint8 flag);
extern int32
_sys_usw_qos_remove_mcast_queue_to_channel(uint8 lchip, uint16 lport, uint8 channel);
extern int32
_sys_usw_qos_set_mc_queue_high_priority_en(uint8 lchip);
extern int32
_sys_usw_queue_add_for_stacking(uint8 lchip, uint32 chan_id);
extern int32
_sys_usw_queue_remove_for_stacking(uint8 lchip, uint32 chan_id);
extern uint8
_sys_usw_queue_get_service_queue_mode(uint8 lchip);
extern int32
_sys_usw_qos_bind_service_logic_dstport(uint8 lchip, uint16 service_id, uint16 logic_dst_port, uint32 gport,uint32 nexthop_ptr);
extern int32
_sys_usw_qos_unbind_service_logic_dstport(uint8 lchip, uint16 service_id, uint16 logic_dst_port, uint32 gport);
extern int32
_sys_usw_qos_bind_service_logic_srcport(uint8 lchip, uint16 service_id, uint16 logic_port);
extern int32
_sys_usw_qos_unbind_service_logic_srcport(uint8 lchip, uint16 service_id, uint16 logic_port);
extern int32
sys_usw_get_channel_agg_group(uint8 lchip, uint16 chan_id, uint8* chanagg_id);

extern int32
_sys_usw_get_channel_by_port(uint8 lchip, uint32 gport, uint16 *channel);
extern int32
_sys_usw_add_port_to_channel(uint8 lchip, uint32 lport, uint16 channel, uint8 is_pp);
extern int32
_sys_usw_remove_port_from_channel(uint8 lchip, uint32 lport);
extern int32
sys_usw_set_priority_queue_select(uint8 lchip,
                                        uint8 priority,
                                        uint8 queue_select);
extern int32
_sys_usw_set_dma_channel_drop_en(uint8 lchip, bool enable);
extern int32
_sys_usw_qos_set_aqmscan_high_priority_en(uint8 lchip, bool enable);
extern int32
sys_usw_queue_stats_query(uint8 lchip, ctc_qos_queue_stats_t* p_stats);
extern int32
sys_usw_queue_stats_clear(uint8 lchip, ctc_qos_queue_stats_t* p_stats);
extern int32
sys_usw_qos_query_stats(uint8 lchip, ctc_qos_stats_type_t type, void* p_stats);
extern int32
sys_usw_qos_clear_stats(uint8 lchip, ctc_qos_stats_type_t type, void* p_stats);
extern int32
_sys_usw_queue_traverse_queue_node(uint8 lchip, uint16 lport,
                                SYS_QOS_TRAVERSE_FUNC fn,
                                void* user_data);
extern int32
sys_usw_qos_set_monitor_drop_queue_id(uint8 lchip,  ctc_qos_queue_drop_monitor_t* drop_monitor, sys_nh_info_dsnh_t* p_nhinfo);
extern int32
sys_usw_qos_get_monitor_drop_queue_id(uint8 lchip,  ctc_qos_queue_drop_monitor_t* drop_monitor);
extern int32
sys_usw_qos_alloc_monitor_drop_reason_queue_id(uint8 lchip, sys_cpu_reason_dest_info_t *p_dest_info);
extern int32
sys_usw_qos_free_monitor_drop_reason_queue_id(uint8 lchip);
extern int32
sys_usw_qos_map_token_rate_hw_to_user(uint8 lchip, uint8 is_pps,
                                            uint32 hw_rate,
                                            uint32 *user_rate,
                                            uint16 bit_with,
                                            uint32 upd_freq,
                                            uint16 pps_pkt_byte);
extern int32
sys_usw_qos_map_token_rate_user_to_hw(uint8 lchip, uint8 is_pps,
                                            uint32 user_rate, /*kb/s*/
                                            uint32 *hw_rate,
                                            uint16 bit_with,
                                            uint32 gran,
                                            uint32 upd_freq,
                                            uint16 pps_pkt_byte);
extern int32
_sys_usw_qos_map_token_thrd_hw_to_user(uint8 lchip, uint32  *user_bucket_thrd,
                                            uint32 hw_bucket_thrd,
                                            uint8 shift_bits);
extern int32
_sys_usw_qos_map_token_thrd_user_to_hw(uint8 lchip, uint32  user_bucket_thrd,
                                            uint32 *hw_bucket_thrd,
                                            uint8 shift_bits,
                                            uint32 max_thrd);
extern bool
sys_usw_queue_shp_get_channel_pps_enbale(uint8 lchip, uint16 chand_id);
extern int32
sys_usw_qos_queue_dump_status(uint8 lchip);
extern int32
sys_usw_qos_sched_dump_status(uint8 lchip);
extern int32
sys_usw_qos_policer_dump_status(uint8 lchip);
extern int32
sys_usw_qos_drop_dump_status(uint8 lchip);
extern int32
sys_usw_qos_shape_dump_status(uint8 lchip);
extern int32
_sys_usw_qos_queue_dump(uint8 lchip, uint16 start, uint16 end, uint8 detail);
extern int32
_sys_usw_qos_group_dump(uint8 lchip, uint32 start, uint32 end, uint8 detail);
extern int32
_sys_usw_qos_port_dump(uint8 lchip, uint16 start, uint16 end, uint8 detail);
extern int32
_sys_usw_qos_service_dump(uint8 lchip, uint16 service_id, uint32 gport);
extern int32
_sys_usw_qos_dump_status(uint8 lchip);
extern int32
sys_usw_queue_wb_sync(uint8 lchip, uint32 appid, ctc_wb_data_t *p_wb_data);
extern int32
sys_usw_queue_wb_restore(uint8 lchip, ctc_wb_query_t *p_wb_query);
extern int32
sys_usw_qos_queue_dump_db(uint8 lchip, sal_file_t p_f,ctc_global_dump_db_t* p_dump_param);
extern int32
sys_usw_queue_enq_init(uint8 lchip, void* p_glb_parm);
extern int32
sys_usw_queue_enq_deinit(uint8 lchip);

/****************************** queue shape ******************************/
extern int32
_sys_usw_queue_shp_alloc_profileId(sys_queue_shp_profile_t* p_node, uint8* p_lchip);
extern int32
_sys_usw_queue_shp_restore_profileId(sys_queue_shp_profile_t* p_node, uint8* p_lchip);
extern int32
_sys_usw_queue_meter_alloc_profileId(sys_queue_meter_profile_t* p_node, uint8* p_lchip);
extern int32
_sys_usw_queue_meter_restore_profileId(sys_queue_meter_profile_t* p_node, uint8* p_lchip);
extern int32
_sys_usw_group_shp_alloc_profileId(sys_group_shp_profile_t* p_node, uint8* p_lchip);
extern int32
_sys_usw_group_shp_restore_profileId(sys_group_shp_profile_t* p_node, uint8* p_lchip);
extern int32
_sys_usw_group_meter_alloc_profileId(sys_group_meter_profile_t* p_node, uint8* p_lchip);
extern int32
_sys_usw_group_meter_restore_profileId(sys_group_meter_profile_t* p_node, uint8* p_lchip);
extern int32
_sys_usw_queue_shp_get_queue_shape_profile_from_asic(uint8 lchip,
                                               sys_queue_shp_profile_t* p_sys_profile);
extern int32
_sys_usw_queue_shp_get_queue_meter_profile_from_asic(uint8 lchip,
                                               sys_queue_meter_profile_t* p_sys_profile);
extern int32
_sys_usw_queue_shp_get_group_shape_profile_from_asic(uint8 lchip,
                                               sys_group_shp_profile_t* p_sys_profile);
extern int32
_sys_usw_queue_shp_get_group_meter_profile_from_asic(uint8 lchip,
                                               sys_group_meter_profile_t* p_sys_meter_profile);
extern int32
_sys_usw_queue_shp_encode_queue_shape_meter_profile(uint8 lchip,
                                                                uint32 thrd, uint32 rate, void* p_ds);
extern int32
_sys_usw_queue_shp_decode_queue_shape_meter_profile(uint8 lchip, uint8 profile_id, void* p_ds,
                                                               uint32 *rate, uint32 *thrd);

extern int32
_sys_usw_queue_shp_get_queue_meter_from_asic(uint8 lchip,
                                       sys_queue_node_t* p_sys_queue, sys_queue_meter_profile_t* p_meter_profile);
extern int32
_sys_usw_queue_shp_get_queue_shape_from_asic(uint8 lchip,
                                       sys_queue_node_t* p_sys_queue, sys_queue_shp_profile_t* p_shp_profile);
int32
_sys_usw_queue_shp_get_group_shape_from_asic(uint8 lchip,
                                       uint8 is_pir, uint16 group_id, uint8* profile_id);
extern int32
_sys_usw_queue_shp_encode_queue_shape_profile(uint8 lchip, uint8 queue_type,
                                                                uint32 thrd, uint32 rate, void* p_ds);
extern int32
_sys_usw_queue_shp_decode_queue_shape_profile(uint8 lchip, uint8 queue_type, uint8 profile_id, void* p_ds,
                                                               uint32 *rate, uint32 *thrd);

extern int32
_sys_usw_qos_set_shape(uint8 lchip, ctc_qos_shape_t* p_shape);
extern int32
_sys_usw_qos_get_shape(uint8 lchip, ctc_qos_shape_t* p_shape);
extern int32
_sys_usw_queue_shp_set_group_shape(uint8 lchip, ctc_qos_shape_group_t* p_shape);
extern int32
sys_usw_qos_set_port_shape_enable(uint8 lchip, uint8 enable);
extern int32
sys_usw_qos_set_queue_shape_enable(uint8 lchip, uint8 enable);
extern int32
sys_usw_qos_set_group_shape_enable(uint8 lchip, uint8 enable);
extern int32
sys_usw_qos_get_port_shape_enable(uint8 lchip, uint32* p_enable);
extern int32
sys_usw_qos_get_queue_shape_enable(uint8 lchip, uint32* p_enable);
extern int32
sys_usw_qos_get_group_shape_enable(uint8 lchip, uint32* p_enable);
extern int32
sys_usw_qos_set_shape_ipg_enable(uint8 lchip, uint8 enable);
extern int32
sys_usw_qos_set_reason_shp_base_pkt_en(uint8 lchip, uint8 enable);
extern int32
sys_usw_qos_set_port_shp_base_pkt_en(uint8 lchip, uint8 enable);
extern int32
sys_usw_qos_set_shape_mode(uint8 lchip, uint8 mode);
extern int32
_sys_usw_qos_get_port_shape_profile(uint8 lchip, uint32 gport, uint32* rate, uint32* thrd, uint8* pps_en, uint8* p_shp_en);
extern int32
sys_usw_queue_shape_init(uint8 lchip);
extern int32
sys_usw_queue_shape_deinit(uint8 lchip);

/****************************** queue sch ******************************/
extern int32
_sys_usw_qos_set_sched(uint8 lchip, ctc_qos_sched_t* p_sched);
extern int32
_sys_usw_qos_get_sched(uint8 lchip, ctc_qos_sched_t* p_sched);
extern int32
_sys_usw_qos_create_sch_group(uint8 lchip, ctc_qos_sched_group_id_t* p_sch_group);
extern int32
_sys_usw_qos_destory_sch_group(uint8 lchip, ctc_qos_sched_group_id_t* p_sch_group);
extern int32
sys_usw_queue_sch_set_group_sched(uint8 lchip, ctc_qos_sched_group_t* p_sched);
extern int32
sys_usw_queue_sch_get_group_sched(uint8 lchip, uint16 sub_grp,ctc_qos_sched_group_t* p_sched);
extern int32
sys_usw_queue_sch_get_queue_sched(uint8 lchip, uint16 queue_id ,ctc_qos_sched_queue_t* p_sched);
extern int32
sys_usw_queue_sch_set_c2c_group_sched(uint8 lchip, uint16 queue_id, uint8 class_priority);
extern int32
sys_usw_qos_set_sch_wrr_enable(uint8 lchip, uint8 enable);
extern int32
sys_usw_queue_sch_init(uint8 lchip);
extern int32
sys_usw_queue_sch_deinit(uint8 lchip);

/****************************** queue drop ******************************/
extern int32
_sys_usw_queue_drop_wtd_alloc_profileId(sys_queue_drop_wtd_profile_t* p_node, uint8* p_lchip);
extern int32
_sys_usw_queue_drop_wred_alloc_profileId(sys_queue_drop_wred_profile_t* p_node, uint8* p_lchip);
extern int32
_sys_usw_queue_drop_wred_restore_profileId(sys_queue_drop_wred_profile_t* p_node, uint8* p_lchip);
extern int32
_sys_usw_qos_fc_alloc_profileId(sys_qos_fc_profile_t* p_node, uint8* p_lchip);
extern int32
_sys_usw_qos_pfc_alloc_profileId(sys_qos_fc_profile_t* p_node, uint8* p_lchip);
extern int32
_sys_usw_queue_get_profile_from_hw(uint8 lchip, uint32 gport, sys_qos_shape_profile_t* p_shp_profile);
extern int32
_sys_usw_queue_set_port_drop_en(uint8 lchip, uint32 chan_id, bool enable, sys_qos_shape_profile_t* p_shp_profile);
extern int32
_sys_usw_queue_get_port_depth(uint8 lchip, uint32 gport, uint32* p_depth);
extern int32
sys_usw_qos_flow_ctl_profile(uint8 lchip, uint32 gport, uint8 cos, uint8 is_pfc, uint8 is_oobfc, uint8 enable);
extern int32
_sys_usw_queue_drop_read_profile_from_asic(uint8 lchip, uint8 wred_mode,
                                             sys_queue_node_t* p_sys_queue,
                                             sys_queue_drop_profile_t* p_sys_profile);
extern int32
sys_usw_qos_fc_get_profile_from_asic(uint8 lchip, uint8 is_pfc, sys_qos_fc_profile_t *p_sys_fc_profile);
extern int32
sys_usw_qos_oobfc_get_profile_from_asic(uint8 lchip, sys_qos_oobfc_profile_t *p_sys_oobfc_profile);
extern int32
sys_usw_qos_fc_get_dropthrd_profile_from_asic(uint8 lchip, uint8 is_pfc, sys_qos_fc_profile_t *p_sys_fc_profile);
extern int32
sys_usw_queue_set_default_drop(uint8 lchip,
                                     uint16 queue_id,
                                     uint8 profile_id);
extern int32
_sys_usw_qos_fc_profile_add_spool(uint8 lchip, uint8 is_pfc, uint8 is_dropthrd, sys_qos_fc_profile_t* p_sys_profile_old,
                                                          sys_qos_fc_profile_t* p_sys_profile_new,
                                                          sys_qos_fc_profile_t** pp_sys_profile_get);
extern int32
_sys_usw_qos_oobfc_profile_add_spool(uint8 lchip, sys_qos_oobfc_profile_t* p_sys_profile_old,
                                                          sys_qos_oobfc_profile_t* p_sys_profile_new,
                                                          sys_qos_oobfc_profile_t** pp_sys_profile_get);
extern int32
_sys_usw_queue_drop_wtd_profile_add_spool(uint8 lchip, sys_queue_drop_wtd_profile_t* p_sys_profile_old,
                                                          sys_queue_drop_wtd_profile_t* p_sys_profile_new,
                                                          sys_queue_drop_wtd_profile_t** pp_sys_profile_get);
extern int32
_sys_usw_queue_drop_wred_profile_add_spool(uint8 lchip, sys_queue_drop_wred_profile_t* p_sys_profile_old,
                                                          sys_queue_drop_wred_profile_t* p_sys_profile_new,
                                                          sys_queue_drop_wred_profile_t** pp_sys_profile_get);
extern int32
_sys_usw_qos_guarantee_profile_add_spool(uint8 lchip, sys_queue_guarantee_t* p_sys_profile_old,
                                                          sys_queue_guarantee_t* p_sys_profile_new,
                                                          sys_queue_guarantee_t** pp_sys_profile_get);
extern int32
_sys_usw_queue_set_egs_resrc_guarantee(uint8 lchip, uint8 enable);
extern int32
sys_usw_queue_get_sc_tc(uint8 lchip, sys_queue_node_t* p_sys_queue, uint8* sc, uint8* tc);

extern int32
sys_usw_queue_set_drop(uint8 lchip, ctc_qos_drop_t* p_drop);
extern int32
sys_usw_queue_get_drop(uint8 lchip, ctc_qos_drop_t* p_drop);
extern int32
sys_usw_queue_set_resrc(uint8 lchip, ctc_qos_resrc_t* p_resrc);
extern int32
sys_usw_queue_get_resrc(uint8 lchip, ctc_qos_resrc_t* p_resrc);
extern int32
sys_usw_queue_query_pool_stats(uint8 lchip, ctc_qos_resrc_pool_stats_t* p_stats);
extern int32
sys_usw_qos_resrc_mgr_en(uint8 lchip, uint8 enable);
extern int32
sys_usw_qos_set_oobfc(uint8 lchip, ctc_qos_oobfc_t* p_oobfc_para);
extern int32
sys_usw_qos_get_oobfc(uint8 lchip, ctc_qos_oobfc_t* p_oobfc_para);
extern int32
sys_usw_qos_set_fast_ecn(uint8 lchip, uint32 value);
extern int32
sys_usw_qos_get_fast_ecn(uint8 lchip, uint32* value);
extern int32
sys_usw_qos_set_ecn_enable(uint8 lchip, uint32 enable);
extern int32
sys_usw_qos_get_ecn_enable(uint8 lchip, uint32* enable);
extern int32
sys_usw_qos_set_aqm_port_disable(uint8 lchip, uint32 disable);
extern int32
sys_usw_qos_get_aqm_port_disable(uint8 lchip, uint32* disbale);
extern int32
sys_usw_queue_drop_init(uint8 lchip, void *p_glb_parm);
extern int32
sys_usw_queue_drop_deinit(uint8 lchip);
extern int32
sys_usw_qos_set_resrc_check_mode(uint8 lchip, uint8 mode);
extern int32
sys_usw_qos_set_fcdl_interval(uint8 lchip, uint32 time);
extern int32
sys_usw_qos_set_port_policer_stbm_enable(uint8 lchip, uint8 enable);
extern int32
_sys_usw_queue_drop_read_asic(uint8 lchip, uint8 wred_mode, sys_queue_node_t *p_queue_node,
                                                 sys_queue_drop_profile_t* p_sys_profile, uint8* hw_valid);

extern int32
sys_usw_qos_fcdl_timer_en(uint8 lchip, uint8 enable);
extern int32
sys_usw_qos_set_fcdl_action(uint8 lchip, uint32 action);
extern int32
sys_usw_qos_get_fcdl_action(uint8 lchip, uint32* action);
extern int32
_sys_usw_queue_set_resrc_use_cnt_min(uint8 lchip, uint8 min);
/****************************** cpu reason ******************************/
extern int32
sys_usw_queue_get_excp_idx_by_reason(uint8 lchip, uint16 reason_id,
                                            uint16* excp_idx,
                                            uint8* excp_num);
extern int32
_sys_usw_cpu_reason_get_reason_info(uint8 lchip, uint8 dir,
                                          sys_cpu_reason_info_t* p_cpu_rason_info);
extern int32
_sys_usw_cpu_reason_free_exception_index(uint8 lchip, uint8 dir,
                                            sys_cpu_reason_info_t* p_cpu_rason_info);
extern int32
_sys_usw_cpu_reason_alloc_exception_index(uint8 lchip, uint8 dir,
                                            sys_cpu_reason_info_t* p_cpu_rason_info);
int32
sys_usw_cpu_reason_update_exception(uint8 lchip, uint16 reason_id, sys_cpu_reason_dest_info_t* p_dest_info);
extern int32
sys_usw_cpu_reason_set_map(uint8 lchip, uint16 reason_id,
                                  uint8 sub_queue_id,
                                  uint8 group_id,
                                  uint8 acl_match_group,
                                  sys_cpu_reason_dest_info_t* dest_info);
extern int32
sys_usw_cpu_reason_get_map(uint8 lchip, uint16 reason_id,uint8* sub_queue_id,uint8* group_id,uint8* acl_match_group);
extern int32
sys_usw_cpu_reason_set_dest(uint8 lchip, uint16 reason_id, sys_cpu_reason_dest_info_t* dest_info);
extern int32
_sys_usw_qos_queue_bind_cpu_reason(uint8 lchip, uint16 reason_id);
extern int32
_sys_usw_cpu_reason_encode_dest_info(uint8 lchip, uint16 reason_id, sys_cpu_reason_dest_info_t* dest_info);
extern int32
sys_usw_cpu_reason_set_truncation(uint8 lchip, uint16 reason_id, uint16 truncated_len);
extern int32
sys_usw_cpu_reason_get_truncation(uint8 lchip, uint16 reason_id, uint16* truncated_len);
extern int32
sys_usw_cpu_reason_get_truncation(uint8 lchip, uint16 reason_id, uint16* truncated_len);
extern int32
_sys_usw_get_sub_queue_id_by_cpu_reason(uint8 lchip, uint16 reason_id, uint16* sub_queue_id);
extern int32
sys_usw_cpu_reason_set_misc_param(uint8 lchip, uint16 reason_id, uint32 truncatd_len);

extern int32
_sys_usw_cpu_reason_get_info(uint8 lchip, uint16 reason_id, sys_cpu_reason_dest_info_t* p_dest_info);
extern int32
_sys_usw_cpu_reason_set_info(uint8 lchip, uint16 reason_id, sys_cpu_reason_dest_info_t* p_dest_info);

extern int32
_sys_usw_qos_cpu_reason_dump(uint8 lchip, uint16 start, uint16 end, uint8 detail);
extern int32
sys_usw_queue_cpu_reason_init(uint8 lchip);
extern int32
sys_usw_queue_cpu_reason_deinit(uint8 lchip);
extern int32
_sys_usw_qos_set_fc_default_profile(uint8 lchip, uint32 gport);
extern int32
sys_usw_exception_update_trunk_by_rchip(uint8 lchip, uint8 remote_gchip, uint8 trunk_id);

#ifdef __cplusplus
}
#endif

#endif

